<?php
class Hydrum_Application_Resource_Modules extends Zend_Application_Resource_ResourceAbstract
{
    public function init()
    {
        $modules = new Hydrum_Module_Collection();
        
        $bootstrap = $this->getBootstrap();
        $bootstrap->bootstrap('pathfinder');

        $pathfinder = $bootstrap->getResource('pathfinder');

        $paths = $pathfinder->find('configs/modules')->lookup('\.xml$');

        foreach ($paths as $path) {

            $config = new Zend_Config_Xml($path);

            $code = preg_replace('/\.xml$/i', '', basename($path));

            $modules->set($code, new Hydrum_Module($code, $config));
        }

        return $modules;
    }
}
